package org.sean.framework.es;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserIndex extends BaseEntityIndex<User> {

    private static final String VERSION = "_tmp";
    private static final String REAL_INDEX = "user" + VERSION;

    @Override
    public boolean createIndex() {
        Map<String, Object> properties = new HashMap<>();

        // ID
        Map<String, Object> id = new HashMap<>();
        id.put("type", "integer");
        properties.put("id", id);

        // 名称
        Map<String, Object> name = new HashMap<>();
        name.put("type", "keyword");
        properties.put("name", name);

        // 手机号
        Map<String, Object> phone = new HashMap<>();
        phone.put("type", "keyword");
        properties.put("phone", phone);
        return operation.createIndex(REAL_INDEX, properties);
    }

    @Override
    protected String getIndexName() {
        return REAL_INDEX;
    }

    public void delIndex() {
        deleteIndex(REAL_INDEX);
    }
}
